﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for ArticleDAL
/// </summary>
public class ArticleDAL
{
    DataAccess da = new DataAccess();
    //Update Article
    public int Update_Article_DAL(Article art,Article_Description art_des)
    {
        SqlParameter[] paramList = new SqlParameter[10];
        paramList[0] = da.AddParameter("article_id",art.article_id, SqlDbType.Int, null);
        paramList[1] = da.AddParameter("author", art_des.author, SqlDbType.NVarChar, null);
        paramList[2] = da.AddParameter("article_name", art_des.article_name, SqlDbType.NVarChar, null);
        paramList[3] = da.AddParameter("article_sumary", art_des.article_sumary, SqlDbType.NVarChar, null);
        paramList[4] = da.AddParameter("article_des", art_des.article_des, SqlDbType.Text, null);
        paramList[5] = da.AddParameter("image", art.image, SqlDbType.NVarChar, null);
        paramList[6] = da.AddParameter("category_id", art.category_id, SqlDbType.Int, null);
        paramList[7] = da.AddParameter("topic_id", art.topic_id, SqlDbType.Int, null);
        paramList[8] = da.AddParameter("status", art.status, SqlDbType.Bit, null);
        paramList[9] = da.AddParameter("language_id", art_des.language_id, SqlDbType.Int, null);
        return da.executeUpdate("UPDATE_Article", paramList);
    }
    

    public DataTable Get_All_Article()
    {
        return da.executeSelect("SL_View_Article");
    }

    public DataTable Get_Article_By_Id_Category_DAL(Article art)
    {
        SqlParameter[] paramList = new SqlParameter[1];
        paramList[0] = da.AddParameter("category_id", art.category_id, SqlDbType.Int, null);
        return da.executeSelect("SL_View_Article", paramList);
    }

    public DataTable Get_Article_By_Id_DAL(Article art){
        SqlParameter[] paramList = new SqlParameter[1];
        paramList[0] = da.AddParameter("article_id", art.article_id,SqlDbType.Int, null);
        return da.executeSelect("SL_View_Article", paramList);
    }

    public DataTable getArticleOrderByDate(int language_id,int top)
    {
        SqlParameter[] paramList = new SqlParameter[3];
        paramList[0] = da.AddParameter("language_id", language_id, SqlDbType.Int, null);
        paramList[1] = da.AddParameter("category_id", DBNull.Value, SqlDbType.Int, null);
        paramList[2] = da.AddParameter("top", top, SqlDbType.Int, null);
        return da.executeSelect("GET_ARTICLE_DATE",paramList);
    }

    public DataTable getArticleByCategoryID(int language_id,int category_id, int top)
    {
        SqlParameter[] paramList = new SqlParameter[3];
        paramList[0] = da.AddParameter("language_id", language_id, SqlDbType.Int, null);
        paramList[1] = da.AddParameter("category_id", category_id, SqlDbType.Int, null);
        paramList[2] = da.AddParameter("top", top, SqlDbType.Int, null);
        return da.executeSelect("GET_ARTICLE_DATE", paramList);
    }

    public int Delete_Article(int article_id) {
        SqlParameter[] paramList = new SqlParameter[1];
        paramList[0] = da.AddParameter("article_id", article_id, SqlDbType.Int, null);
        return da.executeUpdate("UPDATE_Article", paramList);
    }

    public DataTable getArticleByID(int language_id, int article_id)
    {
        SqlParameter[] paramList = new SqlParameter[4];
        paramList[0] = da.AddParameter("language_id", language_id, SqlDbType.Int, null);
        paramList[1] = da.AddParameter("category_id", DBNull.Value, SqlDbType.Int, null);
        paramList[2] = da.AddParameter("top", DBNull.Value, SqlDbType.Int, null);
        paramList[3] = da.AddParameter("article_id", article_id, SqlDbType.Int, null);
        return da.executeSelect("GET_ARTICLE_DATE", paramList);
    }
  
}